package src.E_Thread;

// 线程礼让
// 让正在执行的线程暂停但不阻塞，从运行状态转为就绪状态，让cpu重新调度，礼让不一定成功看cpu心情
public class E10_ThreadYield implements Runnable{
    public static void main(String[] args) {
        new Thread(new E10_ThreadYield(),"A").start();
        new Thread(new E10_ThreadYield(),"B").start();
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+" :began");
        Thread.yield(); // 礼让
        System.out.println(Thread.currentThread().getName()+" :end");
    }
}
